using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tavis.Tools {
    [TestClass]
    public class PathWalkerTests {

        [TestMethod]
        public void Walk_Path() {

            var path = new PathWalker("SalesOrder/Customer/Code");

            Assert.AreEqual("", path.ProcessedPath);
            Assert.AreEqual("SalesOrder/Customer/Code", path.UnprocessedPath);

            path.Position++;

            Assert.AreEqual("SalesOrder", path.ProcessedPath);
            Assert.AreEqual("Customer/Code", path.UnprocessedPath);

            path.Position++;

            Assert.AreEqual("SalesOrder/Customer", path.ProcessedPath);
            Assert.AreEqual("Code", path.UnprocessedPath);
            path.Position++;

            Assert.AreEqual("SalesOrder/Customer/Code", path.ProcessedPath);
            Assert.AreEqual("", path.UnprocessedPath);

        }

        [TestMethod]
        public void PathWalker_should_return_isLastPosition_false_when_not() {

            //Arrange
            var path = new PathWalker("/Bob/Bill/Fred");

            // Act
            var islast = path.IsLastPosition();

            //Assert
            Assert.IsFalse(islast);
        }


        [TestMethod]
        public void PathWalker_should_return_isLastPosition_true_when_is() {

            //Arrange
            var path = new PathWalker("Bob/Bill/Fred");

            // Act
            path.Position++;
            path.Position++;
            var islast = path.IsLastPosition();

            //Assert
            Assert.AreEqual("Fred", path.CurrentSegment);
            Assert.IsTrue(islast);
        }

        [TestMethod]
        public void PathWalker_with_root_slash_counts_as_Segment() {

            //Arrange


            // Act
            var path = new PathWalker("/Bob");

            //Assert
            Assert.AreEqual("", path.CurrentSegment);
            Assert.IsFalse(path.IsLastPosition());
        }




    }
}
